package com.rongzhe.house.common.utils;
import org.apache.commons.lang3.RandomStringUtils;

/**
 * <p>Description: 密码加密  </p>
 * <p>email: ypasdf@163.com</p>
 * <p>Copyright: Copyright (c) 2018</p>
 *
 * @author yangpeng  2018/2/12
 * @version 1.0
 * @since 1.8
 */
public class PasswordUtil {

    /**
     * 盐值随机字符串个数
     */
    private static final int SALT_COUNT = 8;

    /**
     * 密码加密
     *
     * @param password 密码
     * @param salt     盐值
     * @return
     */
    public static String encrypt(String password, String salt) {
        return SHA1.getSHA256Str(MD5Util.MD5(salt + password)+salt);
    }

    /**
     * 随即生成盐值
     *
     * @return 盐值
     */
    public static String randomSalt() {
        return RandomStringUtils.randomAlphabetic(SALT_COUNT);
    }


    public static void main(String[] args) {
        String salt = "OobeWIDK";
        String encrypt = encrypt("15123309443", salt);
        System.out.println(encrypt);
        System.out.println(salt);
    }
}
